
require 'appwiki/base/base_route.rb'
require 'appwiki/note/note.rb'

class NoteRoute < BaseRoute
  def self.get_handlerpath(request,response,requestpath)
    # where to look for the controller.rb and .rhtml files
    handlerpath = nil
    # where to fetch media assets (everything excepting controller.rb and .rhtml files)
    workingpath = nil
    # /notename/notename/notename/[method name]
    if requestpath.length > 1
      # skip the domain name, look at just local name portion
      subject,subjectpath = Note.find_best_by_tokens(nil,requestpath[1..-1])
      if subject
        # there's a path and an associated handler, use the supplied handler.
        subject.handler = 'note' if !subject.handler
        workingpath = requestpath[0..0] + subjectpath
        handlerpath = requestpath[0..0] + subject.handler.split("/")
      else
        # there's a path but no handler, so use note itself as the handler.
        workingpath = requestpath[0..1]
        handlerpath = requestpath[0..0] + ['note']
      end
    end
    return handlerpath,workingpath,requestpath
  end
end
